﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>批次派报检信息查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'批次派报检信息查询报表'"></vue2-report-header>
    <!-- 查询条件区 -->
    <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :rules="rules" style="margin: 10px"
      :label-position="'left'">
      <el-form-item label="组织结构:" prop="selectOrg">
        <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
          v-model="queryInfo.selectOrg" clearable style="width:300px;" @change="selectOrgChange">
        </el-cascader>
      </el-form-item>

      <el-form-item prop='productname' label="零件图号:">
        <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
          style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
        </el-autocomplete>
      </el-form-item>

      <el-form-item prop='containername' label="流水卡号:">
        <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
          style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
        </el-autocomplete>
      </el-form-item>

      <el-form-item label="派工人:">
        <el-select v-model="queryInfo.dispatcher" placeholder="请选择" clearable filterable style="width:120px;">
          <el-option v-for="w in dispatcherList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="领工人:">
        <el-select v-model="queryInfo.reveiver" placeholder="请选择" clearable filterable style="width:120px;">
          <el-option v-for="w in workerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="报工人:">
        <el-select v-model="queryInfo.worker" placeholder="请选择" clearable filterable style="width:120px;">
          <el-option v-for="w in workerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="检验员:">
        <el-select v-model="queryInfo.checker" placeholder="请选择" clearable filterable style="width:120px;">
          <el-option v-for="w in checkerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="工序号:">
        <el-input v-model.trim="queryInfo.specno" placeholder="请输入" clearable style="width: 100px;"></el-input>
      </el-form-item>

      <el-form-item label="机型:">
        <el-select v-model="queryInfo.productfamilyname" placeholder="请选择" clearable filterable style="width: 120px;">
          <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
            :value="i.productfamilyname">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="派工时间:">
        <el-date-picker v-model="queryInfo.dispatchdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>

      <el-form-item label="领工时间:">
        <el-date-picker v-model="queryInfo.reveivedate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>

      <el-form-item label="报工时间:">
        <el-date-picker v-model="queryInfo.reportdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>

      <el-form-item label="检验时间:">
        <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>

      <el-form-item label="状态:">
        <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width: 100px;">
          <el-option :key="'待报工'" :label="'待报工'" :value="'待报工'"></el-option>
          <el-option :key="'待检验'" :label="'待检验'" :value="'待检验'"></el-option>
          <el-option :key="'已完工'" :label="'已完工'" :value="'已完工'"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="包含备注信息:">
        <el-select v-model="queryInfo.shownotes" placeholder="请选择" style="width:80px;">
          <el-option :key="'否'" :label="'否'" :value="'否'"></el-option>
          <el-option :key="'是'" :label="'是'" :value="'是'"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="关键序:">
        <el-select v-model="queryInfo.iskey" placeholder="请选择" style="width:80px;">
          <el-option :key="'全部'" :label="'全部'" :value="null"></el-option>
          <el-option :key="'是'" :label="'是'" :value="1"></el-option>
          <el-option :key="'否'" :label="'否'" :value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="特性类型:">
        <el-select v-model="queryInfo.charactertype" placeholder="请选择" style="width:80px;">
          <el-option :key="'全部'" :label="'全部'" :value="null"></el-option>
          <el-option :key="'一般件'" :label="'一般件'" :value="'一般件'"></el-option>
          <el-option :key="'重要件'" :label="'重要件'" :value="'重要件'"></el-option>
          <el-option :key="'关键件'" :label="'关键件'" :value="'关键件'"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
      element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip height="640"
      :default-sort="{prop:'containername',order:'descending'}">
      <el-table-column type="index" width="40"></el-table-column>
      <el-table-column prop="datasource" label="数据来源" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="mfgordername" label="订单号" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column prop="familylistnames" label="机型" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workcentername" label="主制工区" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column prop="containername" label="流水卡号" width="160" sortable show-overflow-tooltip></el-table-column>
      <el-table-column prop="workflowstepname" label="工序" sortable width="100" show-overflow-tooltip></el-table-column>
      <el-table-column prop="iskey" label="关键序" width="60" show-overflow-tooltip></el-table-column>
      <el-table-column prop="status" label="状态" width="80">
        <template slot-scope="scope" v-if="scope.row.status">
          <el-tag v-if="scope.row.status === '待报工'">待报工</el-tag>
          <el-tag v-else-if="scope.row.status === '待检验'" type='warning'>待检验</el-tag>
          <el-tag v-else-if="scope.row.status === '已完工'" type='success'>已完工</el-tag>
          <el-tag v-else="scope.row.status === '已完工'">{{scope.row.status}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="dispatchemployeename" label="派工人" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="dispatchqty" label="派工数" width="60" show-overflow-tooltip></el-table-column>
      <el-table-column prop="dispatchdate" label="派工时间" width="160" show-overflow-tooltip :formatter="replaceDate">
      </el-table-column>
      <el-table-column prop="receiver" label="领工人" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="receivdate" label="领工时间" width="160" :formatter="replaceDate"></el-table-column>
      <el-table-column prop="reportwaitdays" width="100">
        <template #header>
          <span>领-报间隔分钟数</span>
          <el-tooltip placement="top" effect="dark">
            <template #content>计算工人从【领工】到【报工】所花费的时间，单位为分钟</template>
            <i class="el-icon-info"></i>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="makecycle" label="单件加工时间" width="80"></el-table-column>
      <el-table-column prop="reporttype" width="80">
        <template #header>
          <span>报工方式</span>
          <el-tooltip placement="top">
            <template #content>
              <p>报工方式字段说明：</p>
              <p>当：(报工数 * 加工工时) > 【领-报间隔分钟数】时，值为【连续报工】</p>
              <p>当：(报工数 * 加工工时) ≤ 【领-报间隔分钟数】时，值为【正常报工】</p>
              <p>当无法进行以上运算时，值显示为空</p>
            </template>
            <i class="el-icon-info"></i>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="reportemployeename" label="报工人" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="reportqty" label="报工数" width="60" show-overflow-tooltip></el-table-column>
      <el-table-column prop="reportdate" label="报工时间" width="160" show-overflow-tooltip :formatter="replaceDate">
      </el-table-column>
      <el-table-column prop="tocheck" label="待检人" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="checkemployeename" label="检验员" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="checkdate" label="检验时间" width="160" show-overflow-tooltip :formatter="replaceDate">
      </el-table-column>
      <el-table-column prop="hegeqty" label="合格数" width="80" show-overflow-tooltip>
        <template slot-scope="scope" v-if="scope.row.hegeqty">
          <el-tag type="success">{{scope.row.hegeqty}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="lossqty" label="报废数" width="60" show-overflow-tooltip>
        <template slot-scope="scope" v-if="scope.row.lossqty">
          <el-tag type="danger">{{scope.row.lossqty}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="lossreasonname" label="报废原因" width="100" show-overflow-tooltip></el-table-column>
      <el-table-column prop="productinfo" label="零件号及版本" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workflowinfo" label="工艺及版本" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column prop="charactertype" label="特性类型" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column prop="notes" label="工艺备注" width="80" show-overflow-tooltip></el-table-column>
      <el-table-column label="其他信息" width="80">
        <template slot-scope="scope" v-if="scope.row.datasource === '报工'">
          <el-popover trigger="click" placement="top">
            <p><i class="el-icon-info" style="margin-right: 5px;"></i>班组: {{scope.row.teamname}}</p>
            <p><i class="el-icon-info" style="margin-right: 5px;"></i>派给设备: {{scope.row.dispatchresourcename}}</p>
            <p>
              <i class="el-icon-time" style="margin-right: 5px;"></i>派工开始日期:
              <span v-if="scope.row.plannedstartdate">{{scope.row.plannedstartdate.split('T')[0]}}</span>
            </p>
            <p>
              <i class="el-icon-time" style="margin-right: 5px;"></i>要求完成日期:
              <span v-if="scope.row.plannedfinishdate">{{scope.row.plannedfinishdate.split('T')[0]}}</span>
            </p>
            <p><i class="el-icon-info" style="margin-right: 5px;"></i>零件名称: {{scope.row.productdescription}}</p>
            <div slot="reference">
              <el-tag style="cursor: pointer;">查看</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="queryInfo.currentPage" :page-sizes="[10,20,50]" :page-size="queryInfo.pageSize"
      layout="prev,pager,next,jumper,sizes,total" :total="total">
    </el-pagination>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getProductFamily, getWorkerList, getFactoryUsersByRoleName, getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate, replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate, replaceDate,
        loading: false,
        loadingText: '数据加载中...',
        total: 0,
        productFamilyList: [],// 机型
        dispatcherList: [],// 派工人
        workerList: [],// 报工人
        checkerList: [],// 检验员
        queryInfo: {
          selectOrg: [],// 组织结构
          dispatcher: '',// 派工人
          worker: '',// 操作工
          checker: '',// 检验员
          dispatchdate: '',// 派工时间
          reportdate: '',// 报工时间
          checkdate: '',// 检验时间
          productfamilyname: '',// 机型
          status: '',// 状态
          specno: '',// 工序号
          productname: '',// 零件图号
          containername: '',// 流水卡号
          shownotes: '否',
          spectypename: '',
          charactertype: null,
          iskey: null,
          reveiver: '',//领工人
          reveivedate: '',//领工时间
          currentPage: 1,//当前页
          pageSize: 10,//每页显示条数
        },
        dataList: [],
        orginazition: [],
        userInfo: {},
        rules: { selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        async selectOrgChange(val) {
          this.queryInfo.worker = null;
          this.queryInfo.dispatcher = null;
          this.queryInfo.checker = null;
          if (val) {
            const [factoryid, workcenterid, teamid] = val;
            this.workerList = await getWorkerList({ factoryid, workcenterid, teamid });
            this.checkerList = await getFactoryUsersByRoleName({ factoryid, rolename: '检验员' });
            this.dispatcherList = await getFactoryUsersByRoleName({ factoryid, rolename: '工区长|班组长' });
          }
        },
        // 查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/report/ContainerStepRecord.ashx?action=getData',
                data: { type: 'getData', ...this.queryInfo }
              });
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/ContainerStepRecord.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        //监听 页码值 改变的事件
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        //监听 pagesize 改变的事件
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.dispatchdate = [startOfThisMonth, endOfThisMonth];

        this.productFamilyList = await getProductFamily();
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.userInfo;
        this.orginazition = await getMESOrginazition({ factoryCode: '600|601|602|604|607|608|609' });
        if (this.orginazition.some(i => i.value === factoryid)) {
          this.queryInfo.selectOrg = [factoryid];
          this.workerList = await getWorkerList({ factoryid });
          this.checkerList = await getFactoryUsersByRoleName({ factoryid, rolename: '检验员' });
          this.dispatcherList = await getFactoryUsersByRoleName({ factoryid, rolename: '工区长|班组长' });
        }
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>